import { defineStore } from 'pinia';
import { getArticleList, getArticleDetail } from '@/api/article';

export const useArticleStore = defineStore('article', {
  state: () => ({
    articleList: [],
    total: 0,
    currentArticle: null
  }),
  
  actions: {
    async getArticleList(pageNum = 1, pageSize = 6) {
      try {
        const res: any = await getArticleList({ pageNum, pageSize });
        this.articleList = res.records;
        this.total = res.total;
        return res;
      } catch (error) {
        return Promise.reject(error);
      }
    },
    
    async getArticleDetail(id: number) {
      try {
        const res = await getArticleDetail(id);
        this.currentArticle = res;
        return res;
      } catch (error) {
        return Promise.reject(error);
      }
    }
  }
}); 